package com.share.rabbitmq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * author:caifan
 * date:2020/3/1
 */
public class RabbitMQConnection {

    /**
     * 创建连接
     * @return
     * @throws Exception
     */
    public static Connection connect() throws Exception {
        //创建连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.2.15");
//        connectionFactory.setPort(5672);
        connectionFactory.setPort(5670);
        connectionFactory.setVirtualHost("my");
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");
        connectionFactory.setConnectionTimeout(1000000);

        //创建连接
        return connectionFactory.newConnection();
    }
}
